import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { listMenu } from '@/api/system/menu';

export function useSubMenu() {
  const route = useRoute();
  const routerId = route?.meta?.id;
  const routeName = route?.meta?.title;
  const subMenu = ref([]);
  const getSubMenu = async (menuId) => {
    let res = await listMenu({ parentId: menuId || routerId });
    if (!res.data) return;
    subMenu.value = res.data;
  };
  return {
    routerId,
    routeName,
    subMenu,
    getSubMenu,
  };
}
